home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / database / pcjunk.c < prev    next >
Text File  |  1985-06-28  |  2KB  |  110 lines

  1. /*  PCJUNK.C     Misc. procedures */
  2.  
  3. #include "stdio.h"
  4. #include "sdbio.h"
  5. #define ESC 27
  6. #define BS 8
  7. #define CR 13
  8. #define LF 10
  9.  
  10. /*    Replaces JUNK.C for the IBM/PC version            dns */
  11.  
  12.  
  13. char *alloc(n)
  14. int n;
  15. {
  16.    return (char*) malloc(n);
  17. }
  18. /* commented out because it doesn't work right replaced with the
  19.    getcx from the original sdb
  20. */
  21. int getcx(fp)
  22.   FILE *fp;
  23. {
  24.     static char buf[LINEMAX] = {0};
  25.     static int  bufptr = 0;
  26.     static int  buflen = 0;
  27.     int ch, i, j;
  28.  
  29.     if (fp!=stdin)
  30.        if ((ch = fgetc(fp)) == '\n')
  31.           return(fgetc(fp));
  32.        else
  33.           return(ch);
  34.  
  35.     if (buflen > 0 && bufptr < buflen)
  36.       if (bufptr == buflen-1)
  37.         {
  38.         i = bufptr ;
  39.         bufptr = 0 ;
  40.         buflen = 0 ;
  41.         return (buf[i]) ;
  42.         }
  43.       else
  44.         {
  45.         return (buf[bufptr++]);
  46.         } ;
  47.  
  48.     bufptr = 0 ;
  49.     buflen = 0 ;
  50.     for (bufptr = 0; (ch = getch() ) != -1; )
  51.         if (bufptr < LINEMAX)
  52.           switch (ch)
  53.             {
  54.             case ESC:
  55.               bufptr=0;
  56.               buflen = 0 ;
  57.               printf("\\\n     ");
  58.               fflush(stdout);
  59.               break ;
  60.             case BS:
  61.               if (bufptr>0)
  62.                 {
  63.                 bufptr-- ;
  64.                 buflen-- ;
  65.                 putch(ch) ;
  66.                 putch(32) ;
  67.                 putch(ch) ;
  68.                 }
  69.               break ;
  70.             case CR:
  71.               putch(13) ;
  72.               putch(10) ;
  73.               if (buflen == 0)
  74.                 return(10) ;
  75.               else
  76.                 {
  77.                 buf[bufptr] = 10 ;
  78.                 buflen++ ;
  79.                 bufptr = 1 ;
  80.                 return(buf[0]) ;
  81.                 }
  82.               break ;
  83.             default:
  84.               buf[bufptr++] = ch;
  85.               buflen++ ;
  86.               putch(ch) ;
  87.               break ;
  88.             }
  89.         else {
  90.             printf("*** line too long ***\nRetype> ");
  91.             fflush( stdout ) ;
  92.             buflen = 0;
  93.             bufptr = 0;
  94.         };
  95.  }
  96.  int strncmp( str1, str2, len)
  97.  char *str1, *str2 ;
  98.  int  len ;
  99.  {
  100.    char  newstr1[255], newstr2[255] ;
  101.    int  i ;
  102.  
  103.    for ( i = 0 ; i < len ; i++ )
  104.      {
  105.        newstr1[i] = str1[i] ;
  106.        newstr2[i] = str2[i] ;
  107.      }
  108.    return (strcmp( newstr1, newstr2 )) ;
  109. }
  110.